import requests
from loguru import logger


class Merchantcoupon:
    def __init__(self):
        self.token = "platform49b1438261dd475083ca5a9867fcf746"
    def coupon_list(self):
        url = "https://api.admin.merchant.java.crmeb.net/api/admin/merchant/coupon/list"
        headers = {'authori-zation': self.token,}
        params = {
            'page': '1',
            'limit': '20',
            'status': '1',
            'name': '11',
            'type': '',
            'useType': '',
            'category': '1',
            'receiveType': '1',
            'temp': '1756104079',
        }
        logger.info(f"coupon_list接口请求参数:{params},")
        response = requests.get(
            url,
            params=params,
            headers=headers,
        )
        logger.info(f"coupon_list接口响应参数:{response.json()}")
        return response.json()

    def coupon_save(self):
        url = "https://api.admin.merchant.java.crmeb.net/api/admin/merchant/coupon/save"
        headers = {'authori-zation': self.token,}
        json_data = {
            'category': 1,
            'isFixedTime': False,
            'name': '1111',
            'money': 1,
            'minPrice': 0,
            'day': 1,
            'isTimeReceive': False,
            'productIds': '',
            'receiveType': 2,
            'isLimited': False,
            'useStartTime': '',
            'useEndTime': '',
            'receiveStartTime': '',
            'receiveEndTime': '',
            'sort': 1,
            'total': 0,
            'status': False,
            'checked': [],
        }
        logger.info(f"coupon_save接口请求参数:{json_data},")
        response = requests.post(
            url,
            headers=headers,
            json=json_data,
        )
        logger.info(f"coupon_save接口响应参数:{response.json()}")
        return response.json()

    def coupon_delete(self,id):
        url = f"https://api.admin.merchant.java.crmeb.net/api/admin/merchant/coupon/delete/{id}"
        headers = {'authori-zation': self.token,}
        logger.info(f"coupon_delete接口请求参数:{url},id:{id}")
        response = requests.post( url,headers=headers)
        logger.info(f"coupon_delete接口响应参数:{response.json()}")
        return response.json()

    def coupon_status(self,id,status):
        url = f"https://api.admin.merchant.java.crmeb.net/api/admin/merchant/coupon/update/status/{id}"
        headers = {'authori-zation': self.token,}
        logger.info(f"coupon_status接口请求参数:{url},id:{id},status:{status}")
        response = (requests.post(url,headers=headers,json={"status":status}))
        logger.info(f"coupon_status接口响应参数:{response.json()}")
        return response.json()

if __name__ == '__main__':
    order = Merchantcoupon()
    order.coupon_list()
    order.coupon_save()
    order.coupon_delete(1329)
    order.coupon_status(1329,1)
    order.coupon_status(1329,0)

